package com.jh.user.pojo;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import com.jh.user.pojo.enums.ChannelMerType;
import org.apache.commons.lang.StringUtils;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.List;

/**
 * @author Yichuan
 * @version 1.0
 */
public class UserChannelRate implements Serializable {

    private static final long serialVersionUID = 3028215393057619400L;

    public static List<UserChannelRate> transform(List<UserChannelRate> rateList) {
        if (rateList == null || rateList.isEmpty()) {
            return ImmutableList.of();
        }
        List<UserChannelRate> result = Lists.newLinkedList();
        for (UserChannelRate brandRate: rateList) {
            result.add(UserChannelRate.transform(brandRate));
        }
        return result;
    }
    public static UserChannelRate transform(UserChannelRate userChannelRate) {

        userChannelRate.setChannelMerType(ChannelMerType.of(userChannelRate.getChannelMerType()).getDesc());
        return userChannelRate;
    }
    public UserChannelRate supply(Long brandId, Short payType, BigDecimal rate, BigDecimal extraFee, BigDecimal gradeRate,String channelMerType) {
        setBrandId(brandId);
        setPayType(payType);
        setRate(rate);
        setExtraFee(extraFee);
        setGradeRate(gradeRate);
        setChannelMerType(channelMerType);
        return this;
    }

    public static UserChannelRate init(User user, Channel channel) {
        UserChannelRate ucr = new UserChannelRate();
        ucr.setUserId(user.getId());
        ucr.setUserGrade(user.getUserGrade().getValue());
        ucr.setChannelName(channel.getName());
        ucr.setSubName(channel.getSubName());
        ucr.setChannelType(channel.getChannelType());
        ucr.setChannelNo(channel.getChannelNo());
        ucr.setChannelId(channel.getId());

        ucr.setSingleMinLimit(channel.getSingleMinLimit());
        ucr.setSingleMaxLimit(channel.getSingleMaxLimit());
        ucr.setEveryDayMaxLimit(channel.getEveryDayMaxLimit());
        ucr.setMinRate(channel.getMinwithdrawFee());
        ucr.setMinExtraFee(channel.getMinextrafee());
        ucr.setStartTime(channel.getStartTime().substring(0, channel.getStartTime().lastIndexOf(":")));
        ucr.setEndTime(channel.getEndTime().substring(0, channel.getEndTime().lastIndexOf(":")));
        ucr.setCostRate(channel.getCostRate());
        ucr.setStatus(channel.getStatus());
        if (StringUtils.isNotBlank(channel.getChannelMerType())) {
            ucr.setChannelMerType(ChannelMerType.of(channel.getChannelMerType()).getDesc());
        }
        return ucr;
    }

    public UserChannelRate limit(BrandRate brandRate) {
        if (brandRate != null) {
            if (getMinRate() == null) {
                setMinRate(brandRate.getRate());
            }
            if (getMinExtraFee() == null) {
                setMinExtraFee(brandRate.getExtraFee());
            }
        }
        return this;
    }

    // 用户id
    private Long userId;
    // 用户等级
    private Short userGrade;
    // 贴牌id
    private Long brandId;
    // 交易类型
    private Short payType;
    // 渠道id
    private Long channelId;
    // 渠道全名
    private String channelName;
    // 渠道名
    private String subName;
    // 渠道类型
    private String channelType;
    // 渠道码
    private String channelNo;

    private BigDecimal singleMinLimit;
    private BigDecimal singleMaxLimit;
    private BigDecimal everyDayMaxLimit;
    private BigDecimal minRate;
    private BigDecimal minExtraFee;
    private String startTime;
    private String endTime;
    private String costRate;

    private BigDecimal rate;
    private BigDecimal extraFee;
    private BigDecimal gradeRate;
    private String status;

    private String channelMerType;

    public String getChannelMerType() {
        return channelMerType;
    }

    public void setChannelMerType(String channelMerType) {
        this.channelMerType = channelMerType;
    }

    public UserChannelRate() {
        super();
    }

    public Long getUserId() {
        return userId;
    }

    public void setUserId(Long userId) {
        this.userId = userId;
    }

    public Short getUserGrade() {
        return userGrade;
    }

    public void setUserGrade(Short userGrade) {
        this.userGrade = userGrade;
    }

    public Long getBrandId() {
        return brandId;
    }

    public void setBrandId(Long brandId) {
        this.brandId = brandId;
    }

    public Short getPayType() {
        return payType;
    }

    public void setPayType(Short payType) {
        this.payType = payType;
    }

    public Long getChannelId() {
        return channelId;
    }

    public void setChannelId(Long channelId) {
        this.channelId = channelId;
    }

    public String getChannelName() {
        return channelName;
    }

    public void setChannelName(String channelName) {
        this.channelName = channelName;
    }

    public String getSubName() {
        return subName;
    }

    public void setSubName(String subName) {
        this.subName = subName;
    }

    public String getChannelType() {
        return channelType;
    }

    public void setChannelType(String channelType) {
        this.channelType = channelType;
    }

    public String getChannelNo() {
        return channelNo;
    }

    public void setChannelNo(String channelNo) {
        this.channelNo = channelNo;
    }

    public BigDecimal getSingleMinLimit() {
        return singleMinLimit;
    }

    public void setSingleMinLimit(BigDecimal singleMinLimit) {
        this.singleMinLimit = singleMinLimit;
    }

    public BigDecimal getSingleMaxLimit() {
        return singleMaxLimit;
    }

    public void setSingleMaxLimit(BigDecimal singleMaxLimit) {
        this.singleMaxLimit = singleMaxLimit;
    }

    public BigDecimal getEveryDayMaxLimit() {
        return everyDayMaxLimit;
    }

    public void setEveryDayMaxLimit(BigDecimal everyDayMaxLimit) {
        this.everyDayMaxLimit = everyDayMaxLimit;
    }

    public BigDecimal getMinRate() {
        return minRate;
    }

    public void setMinRate(BigDecimal minRate) {
        this.minRate = minRate;
    }

    public BigDecimal getMinExtraFee() {
        return minExtraFee;
    }

    public void setMinExtraFee(BigDecimal minExtraFee) {
        this.minExtraFee = minExtraFee;
    }

    public String getStartTime() {
        return startTime;
    }

    public void setStartTime(String startTime) {
        this.startTime = startTime;
    }

    public String getEndTime() {
        return endTime;
    }

    public void setEndTime(String endTime) {
        this.endTime = endTime;
    }

    public String getCostRate() {
        return costRate;
    }

    public void setCostRate(String costRate) {
        this.costRate = costRate;
    }

    public BigDecimal getRate() {
        return rate;
    }

    public void setRate(BigDecimal rate) {
        this.rate = rate;
    }

    public BigDecimal getExtraFee() {
        return extraFee;
    }

    public void setExtraFee(BigDecimal extraFee) {
        this.extraFee = extraFee;
    }

    public BigDecimal getGradeRate() {
        return gradeRate;
    }

    public void setGradeRate(BigDecimal gradeRate) {
        this.gradeRate = gradeRate;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }
}
